<template>
    <section class="wrapper">
      <myHeader :obj="myObj" @events="events"></myHeader>
      <main v-if="applyInfo">
        <section @click="toModifyApply()">
          <myNameCard :bgColor="1" :bool="canModify==0" :faceUrl="applyInfo.HeadUrl">
            <span slot="name">{{applyInfo.Name}}</span>
            <span slot="info">{{applyInfo.Job}}</span>
            <span slot="area">{{applyInfo.Introduce}}</span>
          </myNameCard>
        </section>
        <div class="personWrap_0313">
          <div class="titles_0313">已有 <span> {{applyInfo.ApplyCount}} </span>位用户推荐</div>
          <div class="faceWrap_0313">
            <div class="faces_0313" v-if="applyInfo.ApplyUsers">
              <span class="defaultFace_0313" v-for="item in applyInfo.ApplyUsers" :style="{background:'url(' + (item.HeadUrl?item.HeadUrl:require('../assets/img/expert/icon_my@1.5x.png')) + ') no-repeat center'}"></span>
            </div>
            <p class="userText_0313" v-if="applyInfo.ApplyCount<10">还差{{10-applyInfo.ApplyCount}}个推荐就可以成为行家啦</p>
          </div>
          <div class="share_0313">分享到</div>
        </div>
        <ul class="bottomUL">
          <li @click="showTip"><i class="wx"></i></li>
          <li @click="showTip"><i class="circle"></i></li>
          <li @click="jumpWeb()">
            <i class="sendFriend"></i>
          </li>
        </ul>
      </main>
      <div v-if="tips" class="showTip">
        <span @click="showTip"></span>
      </div>
    </section>
</template>
<script>
import myHeader from './base/myHeader';
import myNameCard from './base/myNameCard';
import { fetch,zdUrl,webUrl,chatAppId } from '../assets/api';
import hgjSkip from '../assets/js/hgjSkip';
import API from '../assets/js/fetchAPI';
import { Toast } from "mint-ui";
import Client from '../assets/js/common';
import {setShare} from '../assets/js/wxConfig';
export default {
  data () {
    return {
      myObj: {
        type: 2,
        text: '成为行家'
      },
      applyInfo:null,
      canModify:0,
      tips:false
    }
  },
  created(){
    hgjSkip.skip().then(res =>{
      this.loginData = res;
      this.getApplyInfo().catch(err=>{
        Toast(err.ErrorInfo);
      });
    });
  },
  methods: {
    events(i){
      if(i==2) {
        history.back();
      }
    },
    async getApplyInfo(){
          let sourceData = await fetch(API.getApplyInfo,this.loginData[1]);
          let resInfo = sourceData.Result;
          Client.setStore('myApplyInfos',resInfo);
          if(!resInfo.ApplyUsers){
            resInfo.ApplyUsers = [];
          }
          let applylen = resInfo.ApplyUsers.length;
          this.canModify = applylen;
          if(applylen<10){
            let arrs=[];
            for(let i=0;i<10-applylen;i++){
              arrs.push({HeadUrl:null});
            }
            resInfo.ApplyUsers = [...resInfo.ApplyUsers,...arrs];
          }
          this.applyInfo = resInfo;
          //console.log('我的行家信息',this.applyInfo);
          setShare({
              title: '行家推荐',
              desc: '请推荐我成为行家',
              link: webUrl + 'verifyPass?sid=' + this.applyInfo.OpenId,
              imgUrl: this.applyInfo.HeadUrl,
              success:function(){
                Toast('分享信息成功');
              }
          });
          Client.setStore('applyInfo',this.applyInfo);
    },
    toModifyApply(){
      if(this.canModify==0){
        this.$router.push({path:'/becomeExpert',query:{modify:true}});
      }
    },
    jumpWeb(){
      let shareData = {CollectUrl:`${webUrl}verifyPass?sid=${this.loginData[1].OpenId}`, CollectTitle:'行家推荐', CollectImgUrl:this.applyInfo.HeadUrl};
      location.href = `${zdUrl}editShare?type=1&AppId=${chatAppId}&OpenId=${this.loginData[1].OpenId}&objs=${encodeURIComponent(JSON.stringify(shareData))}`;
    },
    showTip(){
      this.tips = !this.tips;
    }
  },
  components: {
    myHeader,
    myNameCard
  }
}

</script>
<style lang="less">
.wrapper {
  width: 3.75rem;
  height: 100%;
  .showTip{
    width:100%;
    height:100%;
    position:fixed;
    top:0;
    left:0;
    z-index:10;
    background:rgba(0,0,0,.7);
    span{
      height:100%;
      margin:0 .6rem;
      display: block;
      background:url('../assets/img/expert/shareTip.png') no-repeat center .2rem;
      background-size: contain;
    }
  }
  main {
    padding-top: .44rem;
    height: 100%;
    width: 3.75rem;
    position: absolute;
    top: 0;
    box-sizing: border-box;
    .bottomUL {
      display: flex;
      li {
        width: 33%;
        display: flex;
        align-content: center;
        justify-content: center;
        padding: .2rem 0;
        span{
          display: block;
        }
        i {
          display: block;
          width: .5rem;
          height: .5rem;
          border-radius: 50%;
          &.sendFriend {
            border-radius: 0;
            background: url('../assets/img/expert/Group 4@3x.png') center center;
            background-size: cover;
            background-repeat: no-repeat;
          }
          &.wx {
            background: url('../assets/img/expert/icon_wei@3x.png') center center;
            background-size: cover;
            background-repeat: no-repeat;
          }
          &.circle {
            background: url('../assets/img/expert/icon_p@3x.png') center center;
            background-size: cover;
            background-repeat: no-repeat;
          }
        }
      }
    }
    .personWrap_0313 {
      width: 3.75rem;
      padding: .15rem .15rem 0;
      box-sizing: border-box;
      background: white;
      margin-top: .16rem;
      .share_0313 {
        height: .64rem;
        line-height: .64rem;
        text-align: center;
        background: white;
        font-size: .2rem;
        color: #555;
      }
      .faceWrap_0313 {
        .userText_0313 {
          padding-bottom: .18rem;
          font-size: .14rem;
          color: #555555;
          border-bottom: .01rem solid #E5E5E5;
          text-align: right;
        }
        .faces_0313 {
          padding-top: .18rem;
          overflow: hidden;
          .defaultFace_0313 {
            float: left;
            display: block;
            width: .53rem;
            height: .53rem;
            border-radius: 50%;
            margin-right: .2rem;
            background: url('../assets/img/expert/icon_my@1.5x.png') center center;
            background-size: cover !important;
            background-repeat: no-repeat;
            margin-bottom: .24rem;
            &:nth-of-type(5n){
                margin-right: 0rem;
              }
          }

        }
      }
      
      .titles_0313 {
        height: .54rem;
        border-bottom: .01rem solid #E5E5E5; 
        font-size: .16rem;
        padding-top: .2rem;
        box-sizing: border-box;
        span {
          padding: 0 .03rem;
          color: #557AFF;
        }
      }
    }
  }
}
  
</style>
